package com.yunwaikeji.gy_tool_library.utils.notification;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;

import com.yunwaikeji.gy_tool_library.utils.GYAppUtils;

public class GYNotificationInitBuilder {
    private final Context context;
    private NotificationManager notificationManager;
    private String channelId;
    private String channelName;
    private int importance;

    public GYNotificationInitBuilder(Context context) {
        this.context = context;
        channelName = GYAppUtils.getInfo(context).getName();
        channelId = GYNotificationInfo.NOTIFICATION_CHANNEL_ID;
        importance = NotificationManager.IMPORTANCE_LOW;
    }

    public GYNotificationInitBuilder setChannelId(String channelId) {
        this.channelId = channelId;
        return this;
    }

    public GYNotificationInitBuilder setChannelName(String channelName) {
        this.channelName = channelName;
        return this;
    }

    public GYNotificationInitBuilder setImportance(int importance) {
        this.importance = importance;
        return this;
    }

    public NotificationManager getNotificationManager() {
        return notificationManager;
    }

    public Context getContext() {
        return context;
    }

    public String getChannelId() {
        return channelId;
    }

    public String getChannelName() {
        return channelName;
    }

    public int getImportance() {
        return importance;
    }

    public GYNotificationInitBuilder build() {
        notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // 第三个参数表示通知的重要程度，默认则只在通知栏闪烁一下
            //IMPORTANCE_LOW：默认关闭声音与震动、IMPORTANCE_DEFAULT：开启声音与震动
            NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
            // 注册通道，注册后除非卸载再安装否则不改变
            notificationManager.createNotificationChannel(notificationChannel);
        }
        return this;
    }
}
